package com.yshkj.payment.dto;

import com.yshkj.payment.entity.medicinal.Spec;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;

/**
 * Created by 唐旭 on 2016/10/2.
 */
@Data
public class SpecDto {
    private String uuid;
    //规格名称
    private String name;
    //进价
    private String inPrice;
    //销售价格
    private String outPrice;
    //库存数量
    private int count;
    //物品编码
    private String code;

    public SpecDto() {
    }

    public SpecDto(Spec spec) {
        this.uuid = spec.getUuid();
        this.name = spec.getName();
        if (spec.getInPrice() != null) {
            this.inPrice = spec.getInPrice().toString();
        }
        if (spec.getOutPrice() != null) {
            this.outPrice = spec.getOutPrice().toString();
        }
        this.count = spec.getCount();
        this.code = spec.getCode();
    }

    public void update(Spec spec) {
        spec.setName(this.getName());
        if (!StringUtils.isEmpty(this.getInPrice())) {
            spec.setInPrice(new BigDecimal(this.getInPrice()));
        }
        if (!StringUtils.isEmpty(this.getOutPrice())) {
            spec.setOutPrice(new BigDecimal(this.getOutPrice()));
        }
        spec.setCount(this.count);
        spec.setCode(this.code);
    }
}
